{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在这个教程中，你将会学到怎么用pydeck制作可交互地图可视化  \n",
    "\n",
    "提供的基础数据是：\n",
    "<div class=\"alert alert-info\"><h2>提供的基础数据是：</h2><p>   \n",
    "    数据：<br>  \n",
    "    1.出租车GPS集计栅格OD<br>  \n",
    "\n",
    " </p></div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 什么是deck.gl"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "deck.gl 是一个WebGL支持的框架，用于大型数据集的可视化探索性数据分析。  \n",
    "deck.gl是由uber开发并开源出来的基于WebGL的大数据量可视化框架。它具有提供不同类型可视化图层，GPU渲染的高性能，React和Mapbox GL集成，结合地理信息数据（GPS）的特点。  \n",
    "[deck.gl的官方网站](https://deck.gl)  \n",
    "[deck.gl的官方example](https://deck.gl/#/examples/overview)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-30T09:29:38.760295Z",
     "start_time": "2020-05-30T09:29:38.752319Z"
    }
   },
   "source": [
    "deck.gl提供了python接口，非常方便  \n",
    "[pydeck的官方document](https://pydeck.gl/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 安装"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "安装pydeck\n",
    ">pip install pydeck\n",
    "\n",
    "安装jupyter notebook的pydeck插件  \n",
    ">jupyter nbextension install --sys-prefix --symlink --overwrite --py pydeck  \n",
    "jupyter nbextension enable --sys-prefix --py pydeck"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "deck.gl的地图地图是基于mapbox的，因此各位得申请一个mapbox的apikey，在这个链接  \n",
    "[access token](https://docs.mapbox.com/help/how-mapbox-works/access-tokens/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mapbox_key = '你的mapboxkey'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T01:32:26.355475Z",
     "start_time": "2020-05-31T01:32:25.344173Z"
    }
   },
   "outputs": [],
   "source": [
    "#导入必要的包\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "#导入pydeck\n",
    "import pydeck as pdk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T02:06:20.732514Z",
     "start_time": "2020-05-31T02:06:20.119127Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>VehicleNum</th>\n",
       "      <th>Stime</th>\n",
       "      <th>SLng</th>\n",
       "      <th>SLat</th>\n",
       "      <th>ELng</th>\n",
       "      <th>ELat</th>\n",
       "      <th>Etime</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>22223</td>\n",
       "      <td>00:03:23</td>\n",
       "      <td>114.167465</td>\n",
       "      <td>22.562468</td>\n",
       "      <td>114.225235</td>\n",
       "      <td>22.552750</td>\n",
       "      <td>00:10:48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>22223</td>\n",
       "      <td>00:11:33</td>\n",
       "      <td>114.227150</td>\n",
       "      <td>22.554167</td>\n",
       "      <td>114.229218</td>\n",
       "      <td>22.560217</td>\n",
       "      <td>00:15:19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>22223</td>\n",
       "      <td>00:17:13</td>\n",
       "      <td>114.231354</td>\n",
       "      <td>22.562166</td>\n",
       "      <td>114.255798</td>\n",
       "      <td>22.590967</td>\n",
       "      <td>00:29:06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>22223</td>\n",
       "      <td>00:36:45</td>\n",
       "      <td>114.240196</td>\n",
       "      <td>22.563650</td>\n",
       "      <td>114.119965</td>\n",
       "      <td>22.566668</td>\n",
       "      <td>00:54:42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>22223</td>\n",
       "      <td>01:01:14</td>\n",
       "      <td>114.135414</td>\n",
       "      <td>22.575933</td>\n",
       "      <td>114.166748</td>\n",
       "      <td>22.608267</td>\n",
       "      <td>01:08:17</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   VehicleNum     Stime        SLng       SLat        ELng       ELat  \\\n",
       "0       22223  00:03:23  114.167465  22.562468  114.225235  22.552750   \n",
       "1       22223  00:11:33  114.227150  22.554167  114.229218  22.560217   \n",
       "2       22223  00:17:13  114.231354  22.562166  114.255798  22.590967   \n",
       "3       22223  00:36:45  114.240196  22.563650  114.119965  22.566668   \n",
       "4       22223  01:01:14  114.135414  22.575933  114.166748  22.608267   \n",
       "\n",
       "      Etime  \n",
       "0  00:10:48  \n",
       "1  00:15:19  \n",
       "2  00:29:06  \n",
       "3  00:54:42  \n",
       "4  01:08:17  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#读取OD数据\n",
    "TaxiOD = pd.read_csv(r'data-sample/TaxiOD.csv')\n",
    "TaxiOD.columns = ['VehicleNum', 'Stime', 'SLng', 'SLat', \n",
    "       'ELng', 'ELat','Etime']\n",
    "TaxiOD.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T02:06:21.250130Z",
     "start_time": "2020-05-31T02:06:21.243120Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "464718"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(TaxiOD)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果我们直接可视化46万条数据，pydeck还是一下子没法处理那么多，亲测几万条数据还是可以的，但是上十万就会卡死不显示。  \n",
    "所以这里还是对数据的经纬度保留小数集计后再进行可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T02:06:22.229719Z",
     "start_time": "2020-05-31T02:06:22.159665Z"
    }
   },
   "outputs": [],
   "source": [
    "TaxiOD['SLng'] = TaxiOD['SLng'].round(4)\n",
    "TaxiOD['SLat'] = TaxiOD['SLat'].round(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T02:06:23.212117Z",
     "start_time": "2020-05-31T02:06:23.067235Z"
    }
   },
   "outputs": [],
   "source": [
    "Taxi_O_agg = TaxiOD.groupby(['SLng', 'SLat'])['VehicleNum'].count().reset_index()\n",
    "Taxi_O_agg = Taxi_O_agg[(100<Taxi_O_agg['SLng']) & (Taxi_O_agg['SLng']<180)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 可视化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Hexagon"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[deckgl官方document的HexagonLayer](https://deck.gl/#/documentation/deckgl-api-reference/layers/hexagon-layer?section=coloraggregation-string-optional-)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T02:56:00.110226Z",
     "start_time": "2020-05-31T02:55:58.422981Z"
    }
   },
   "outputs": [],
   "source": [
    "import pydeck \n",
    "# Define a layer to display on a map\n",
    "layer = pydeck.Layer(\n",
    "     'HexagonLayer',\n",
    "    Taxi_O_agg,                                   #数据在此输入\n",
    "    get_position=['SLng', 'SLat'],                #指定经纬度的列\n",
    "    getColorWeight = 'VehicleNum',                #指定集计数量的列\n",
    "    getElevationWeight = 'VehicleNum',            #指定集计数量的列\n",
    "     auto_highlight=True,\n",
    "     elevation_scale=10,\n",
    "     pickable=True,\n",
    "     radius = 200,                                #Hexagon的大小\n",
    "     elevation_range=[0, 500],                    #Hexagon的高低\n",
    "     extruded=True,\n",
    "     coverage=1)                                  #Hexagon覆盖比例\n",
    "\n",
    "# Set the viewport location\n",
    "view_state = pdk.ViewState(\n",
    "    longitude=114.027465,                         #地图底图中心经纬度\n",
    "    latitude=22.632468,                           #地图底图中心经纬度\n",
    "    zoom=10,                                      #地图底图缩放等级\n",
    "    min_zoom=5,\n",
    "    max_zoom=12,\n",
    "    pitch=40,                                     #地图底图俯视角度\n",
    "    bearing=-10)                                  #地图底图选转角度\n",
    "\n",
    "# Render\n",
    "r = pdk.Deck(layers=[layer],                       #创建deckgl实例\n",
    "             initial_view_state=view_state,\n",
    "             mapbox_key = mapbox_key,               #你的mapbox_key\n",
    "             map_style =  'mapbox://styles/mapbox/dark-v9'#mapbox底图的风格\n",
    "            )\n",
    "r.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-30T09:35:39.671131Z",
     "start_time": "2020-05-30T09:35:39.666119Z"
    }
   },
   "source": [
    "<img src=\"https://gitee.com/ni1o1/pygeo-tutorial/raw/master/resource/deckHexagonLayer.png\" style=\"width:1000px\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Heatmap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-30T10:11:51.095702Z",
     "start_time": "2020-05-30T10:11:50.798498Z"
    }
   },
   "outputs": [],
   "source": [
    "import pydeck \n",
    "# Define a layer to display on a map\n",
    "layer = pydeck.Layer(\n",
    "     'HeatmapLayer',\n",
    "    Taxi_O_agg,                                   #数据在此输入\n",
    "    get_position=['SLng', 'SLat'],                #指定经纬度的列\n",
    "    getWeight = 'VehicleNum',                     #指定权重\n",
    "     )\n",
    "\n",
    "# Set the viewport location\n",
    "view_state = pdk.ViewState(\n",
    "    longitude=114.027465,\n",
    "    latitude=22.632468,\n",
    "    zoom=10,\n",
    "    min_zoom=5,\n",
    "    max_zoom=12,\n",
    "    pitch=40,\n",
    "    bearing=-10)\n",
    "\n",
    "# Render\n",
    "r = pdk.Deck(layers=[layer], \n",
    "             initial_view_state=view_state,\n",
    "            mapbox_key = mapbox_key,\n",
    "              map_style =  'mapbox://styles/mapbox/dark-v9'\n",
    "            )\n",
    "r.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"https://gitee.com/ni1o1/pygeo-tutorial/raw/master/resource/deckheatmap.png\" style=\"width:1000px\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ScreenGridLayer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T08:42:11.238822Z",
     "start_time": "2020-05-31T08:42:09.452602Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5625febe06b44dff9dd2c46d0cecb1e6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "DeckGLWidget(json_input='{\"initialViewState\": {\"bearing\": -10, \"latitude\": 22.632468, \"longitude\": 114.027465,…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "import pydeck \n",
    "# Define a layer to display on a map\n",
    "layer = pydeck.Layer(\n",
    "     'ScreenGridLayer',\n",
    "    Taxi_O_agg,                                   #数据在此输入\n",
    "    get_position=['SLng', 'SLat'],                #指定经纬度的列\n",
    "    getWeight = 'VehicleNum',                     #指定权重\n",
    "     opacity =  1,\n",
    "    cellSizePixels = 10,\n",
    "    colorRange = [\n",
    "        [255,255,204,25],\n",
    "        [199,233,180,85],\n",
    "        [127,205,187,127],\n",
    "        [65,182,196,170],\n",
    "        [44,127,184,190],\n",
    "        [37,52,148,255]\n",
    "        ],\n",
    "     )\n",
    "\n",
    "# Set the viewport location\n",
    "view_state = pdk.ViewState(\n",
    "    longitude=114.027465,\n",
    "    latitude=22.632468,\n",
    "    zoom=10,\n",
    "    min_zoom=5,\n",
    "    max_zoom=16,\n",
    "    pitch=40,\n",
    "    bearing=-10)\n",
    "\n",
    "# Render\n",
    "r = pdk.Deck(layers=[layer], \n",
    "             initial_view_state=view_state,\n",
    "            mapbox_key = mapbox_key,\n",
    "              map_style =  'mapbox://styles/mapbox/dark-v9'\n",
    "            )\n",
    "r.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"https://gitee.com/ni1o1/pygeo-tutorial/raw/master/resource/pydeckgrid.png\" style=\"width:1000px\">\n",
    "放大了也能看得比较清楚  \n",
    "<img src=\"https://gitee.com/ni1o1/pygeo-tutorial/raw/master/resource/pydeckgrid2.png\" style=\"width:1000px\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Trips Layer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T03:09:10.075897Z",
     "start_time": "2020-05-31T03:09:08.970855Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "#读取数据\n",
    "data = pd.read_csv(r'data-sample/TaxiData-Sample',header = None)\n",
    "#给数据命名列\n",
    "data.columns = ['VehicleNum', 'Stime', 'Lng', 'Lat', 'OpenStatus', 'Speed']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T03:09:41.649928Z",
     "start_time": "2020-05-31T03:09:13.185582Z"
    }
   },
   "outputs": [],
   "source": [
    "data['coordinates'] = data.apply(lambda r:[r['Lng'],r['Lat']],axis = 1)\n",
    "data['timestamp'] = data['Stime'].str.slice(0,2).astype('int')*3600+data['Stime'].str.slice(3,5).astype('int')*60+data['Stime'].str.slice(6,8).astype('int')\n",
    "data = data.sort_values(by = ['VehicleNum','timestamp'])\n",
    "data['coordinates'] = data['coordinates'].apply(lambda r:[r])\n",
    "data['timestamp'] = data['timestamp'].apply(lambda r:[r])\n",
    "df = data.groupby('VehicleNum')['coordinates','timestamp'].sum()\n",
    "df = df.reset_index()\n",
    "data = data.sort_values(by = 'timestamp')\n",
    "df = pd.DataFrame([[list(data['coordinates'])],[list(data['timestamp'])]]).T\n",
    "df.columns = ['coordinates','timestamp']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T03:12:17.224169Z",
     "start_time": "2020-05-31T03:12:17.129386Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>VehicleNum</th>\n",
       "      <th>coordinates</th>\n",
       "      <th>timestamp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>22271</td>\n",
       "      <td>[[114.266502, 22.728201], [114.266502, 22.7282...</td>\n",
       "      <td>[49, 108, 167, 226, 285, 344, 402, 461, 520, 5...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>22334</td>\n",
       "      <td>[[114.111847, 22.576633], [114.11113, 22.57675...</td>\n",
       "      <td>[32, 52, 64, 84, 104, 124, 144, 164, 184, 204,...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>22396</td>\n",
       "      <td>[[113.996719, 22.693333], [113.995514, 22.6950...</td>\n",
       "      <td>[29, 61, 69, 101, 141, 181, 221, 261, 301, 341...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>22413</td>\n",
       "      <td>[[113.891403, 22.7873], [113.891403, 22.7873],...</td>\n",
       "      <td>[9, 39, 69, 99, 129, 159, 189, 218, 248, 278, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>22437</td>\n",
       "      <td>[[113.852631, 22.588766], [113.853203, 22.5883...</td>\n",
       "      <td>[3, 8, 18, 23, 28, 38, 43, 48, 58, 63, 68, 78,...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   VehicleNum                                        coordinates  \\\n",
       "0       22271  [[114.266502, 22.728201], [114.266502, 22.7282...   \n",
       "1       22334  [[114.111847, 22.576633], [114.11113, 22.57675...   \n",
       "2       22396  [[113.996719, 22.693333], [113.995514, 22.6950...   \n",
       "3       22413  [[113.891403, 22.7873], [113.891403, 22.7873],...   \n",
       "4       22437  [[113.852631, 22.588766], [113.853203, 22.5883...   \n",
       "\n",
       "                                           timestamp  \n",
       "0  [49, 108, 167, 226, 285, 344, 402, 461, 520, 5...  \n",
       "1  [32, 52, 64, 84, 104, 124, 144, 164, 184, 204,...  \n",
       "2  [29, 61, 69, 101, 141, 181, 221, 261, 301, 341...  \n",
       "3  [9, 39, 69, 99, 129, 159, 189, 218, 248, 278, ...  \n",
       "4  [3, 8, 18, 23, 28, 38, 43, 48, 58, 63, 68, 78,...  "
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T08:39:52.795472Z",
     "start_time": "2020-05-31T08:39:49.918171Z"
    }
   },
   "outputs": [],
   "source": [
    "\n",
    "import pydeck as pdk\n",
    "# Define a layer to display on a map\n",
    "layer =  pdk.Layer(\n",
    "    \"TripsLayer\",\n",
    "    df,\n",
    "    get_path='coordinates',\n",
    "    get_timestamps='timestamp',\n",
    "    get_color=[253, 128, 93],\n",
    "    opacity=0.8,\n",
    "    width_min_pixels=5,\n",
    "    rounded=True,\n",
    "    trail_length=600,\n",
    "    current_time=500,\n",
    ")\n",
    "\n",
    "\n",
    "# Set the viewport location\n",
    "view_state = pdk.ViewState(\n",
    "    longitude=114.027465,\n",
    "    latitude=22.632468,\n",
    "    zoom=10,\n",
    "    min_zoom=5,\n",
    "    max_zoom=16,\n",
    "    pitch=40,\n",
    "    bearing=-10)\n",
    "\n",
    "# Render\n",
    "r = pdk.Deck(layers=[layer], \n",
    "             initial_view_state=view_state,\n",
    "            mapbox_key = mapbox_key,\n",
    "              map_style =  'mapbox://styles/mapbox/dark-v9'\n",
    "            )\n",
    "r.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T08:41:49.322255Z",
     "start_time": "2020-05-31T08:41:49.316241Z"
    }
   },
   "source": [
    "<img src=\"https://gitee.com/ni1o1/pygeo-tutorial/raw/master/resource/pydecktrips.png\" style=\"width:1000px\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## GridLayer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-05-31T09:11:34.978151Z",
     "start_time": "2020-05-31T09:11:32.853769Z"
    }
   },
   "outputs": [],
   "source": [
    "layer = pdk.Layer(\n",
    "    \"GridLayer\",      \n",
    "    Taxi_O_agg,                                   #数据在此输入\n",
    "    get_position=['SLng', 'SLat'],                #指定经纬度的列\n",
    "    getWeight = 'VehicleNum',                     #指定权重\n",
    "    pickable=True, \n",
    "    extruded=True, \n",
    "    cell_size=200, \n",
    "    elevation_scale=4,\n",
    "    colorRange = [\n",
    "        [255,255,204,255],\n",
    "        [199,233,180,255],\n",
    "        [127,205,187,255],\n",
    "        [65,182,196,255],\n",
    "        [44,127,184,255],\n",
    "        [37,52,148,255]\n",
    "        ],\n",
    ")\n",
    "\n",
    "# Set the viewport location\n",
    "view_state = pdk.ViewState(\n",
    "    longitude=114.027465,\n",
    "    latitude=22.632468,\n",
    "    zoom=10,\n",
    "    min_zoom=5,\n",
    "    max_zoom=16,\n",
    "    pitch=40,\n",
    "    bearing=-10)\n",
    "\n",
    "# Render\n",
    "r = pdk.Deck(layers=[layer], \n",
    "             initial_view_state=view_state,\n",
    "            mapbox_key = mapbox_key,\n",
    "              map_style =  'mapbox://styles/mapbox/dark-v9'\n",
    "            )\n",
    "r.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"https://gitee.com/ni1o1/pygeo-tutorial/raw/master/resource/pydeckgrids.png\" style=\"width:1000px\">"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
